<%@page import="news.bll.comments.CommentsDaoImpl"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="news.bll.news.*"%>
<%@ page import="news.entity.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'do_deletenews.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    	request.setCharacterEncoding("utf-8");
    	int nid = Integer.parseInt(request.getParameter("nid"));
    	NewsDaoImpl ndi = new NewsDaoImpl();
    	CommentsDaoImpl cdi = new CommentsDaoImpl();
    	List<Comment> comments = cdi.getComments(nid);
    	
    	if(comments.size()>0){
    		cdi.delAllComments(nid);
    	}
    	
   		int result = ndi.delNews(nid);
       	if(result>0){
       		%>
       		<script>
       			alert("新闻删除成功！");
       			window.location="admin.jsp?&pageNo=<%=request.getParameter("pageNo")==null?"":request.getParameter("pageNo") %>";
       		</script>    		
       		<%
       	}else{
       		%>
       		<script>
       			alert("新闻删除失败！");
       			window.location="admin.jsp?&pageNo=<%=request.getParameter("pageNo")==null?"":request.getParameter("pageNo") %>";
       		</script>    		
       		<%
       	}
    	
    	
    %>
  </body>
</html>
